<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$shop=$this->plugin_setting('shop');
$return['shopset']=$shop;
$keywords=$this->plugin_setting('search');
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['id']);
	$selfnumber=$_RQ['selfnumber'];
	if (empty($selfnumber)) {
			exi('请输入预约码!','error','jy_yuyue/worker_hexiao/');
	}
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$order_verify=$this->pdo_get('order',array('id'=>$orderid,'selfnumber'=>$selfnumber));
	if (empty($order_verify)) 
	{
		exi('预约码错误,无权核销','error','jy_yuyue/worker_hexiao/');   
	}
	if($orderid){
		$order=pdo_get('jy_yuyue_order',array('uniacid'=>$uniacid,'id'=>$orderid));
	}else{
		$order=pdo_get('jy_yuyue_order',array('uniacid'=>$uniacid,'id'=>$order_verify['orderid']));
	}
	//核销店员身份
	$prams=array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if (empty($order)) {
			exi('订单不存在!','error','jy_yuyue/worker_hexiao/');
	}
	if($order['status']==0 || $order['status']==4){
		exi('订单未付款或已关闭!','error','jy_yuyue/worker_hexiao/');
	}
	if ($order_verify['status'] >=2) {	
		exi('该预约码已被使用!','error','jy_yuyue/worker_hexiao/');		
	}
	$return['post']=array(
		'orderid'=>$order['id'],
		'selfnumber'=>$selfnumber,
	);
	$user=pdo_get('jy_yuyue_user',array('id'=>$order['user_id'],'uniacid'=>$_SESSION['uniacid']));
	$serve=pdo_get('jy_yuyue_serve',array('id'=>$order['serve_id'],'uniacid'=>$_SESSION['uniacid']));
	$order['user_name']=$user['name'];
	$order['user_mobile']=$user['mobile'];
	$order['serve_title']=$serve['title'];
	$order['serve_image']=$serve['image'];
	$order['package']=json_decode($order['package']);
	$order['createtime']=date('Y-m-d H:i:s', $order['createtime']);
	$serve_times=pdo_getcolumn('jy_yuyue_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['serve_id']),'serve_time');
	$serve_times=json_decode($serve_times,true);
	$order['serve_time']=$serve_times[$order['timeid']];
	if($order['status']==0){
		$order['statustitle']='预约待支付';
		$order['statusdesc']='超时未支付，订单将自动取消';
	}elseif($order['status']==1){
		$order['statustitle']='预约成功';
		$order['statusdesc']='请您留意订单进度';
	}elseif($order['status']==2){
		$order['statustitle']='预约已确认';
		$order['statusdesc']='欢迎下次光临!';
	}elseif($order['status']==3){
		$order['statustitle']='预约已取消';
		$order['statusdesc']='欢迎下次光临！';
	}elseif($order['status']==4){
		$order['statustitle']='预约已完成';
		$order['statusdesc']='欢迎下次光临！';
	}elseif($order['status']==5){
		$order['statustitle']='预约退款中';
		$order['statusdesc']='请您留意退款进度';
	}elseif($order['status']==6){
		$order['statustitle']='预约已退款';
		$order['statusdesc']='感谢您的支持和理解，欢迎下次光临！';
	}else{
		$order['statustitle']='预约已拒绝退款';
		$order['statusdesc']='感谢您的支持和理解，欢迎下次光临！';
	}
	$return['order']=$order;
	set_html('title','核销');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$orderid=intval($post['orderid']);
	$selfnumber=trim($post['selfnumber']);
	$this->model('model')->self_verify($orderid,$_SESSION['uid'],$selfnumber);
	exi('使用成功！','','jy_yuyue/worker_hexiao/');
	
}